package com.grace.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class MyPathListener implements ServletContextListener {
    /*
        当服务器容器启动时，会执行该方法
     */
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();
        String base = servletContext.getContextPath();
        servletContext.setAttribute("base", base);
    }
}
